<pre>
<?php
session_start();
$str = @$_REQUEST["val"];
evl($str);

function evl($str) {
 $str = $str."!";
 $opstack = array();
 $numstack = array();
 $answer = "";
 $p = 0;
 $opr = '()^*/+-!';

 while ($p < strlen($str)) {
 // GET THE NUMBER
 $n = "";
 while ($p < strlen($str)) {
  $c = substr($str,$p,1) ;
  if (strpos('0123456789.',$c) !== FALSE) {
   $n = $n . $c; $p = $p + 1;  
   if ($answer == "") {$answer = $n;}
  } else {break ;}
  if ($answer=="") {$answer=$n;}
 }
 // GET THE OPERATOR
 $o = "";
 while ($p < strlen($str)) {
  $c = substr($str,$p,1) ;
  if (strpos($opr,$c) !== FALSE) {
   $o = $o . $c; $p = $p + 1;  
  } else {break ;}
 }
 // WORK UP THE STACK
 $prev = array_peek($opstack) ;
 if ($prev != "") {
  if (strpos($opr,$prev) <= strpos($opr,$o)) {
   $psv = array_pop($numstack);
   echo "Did this $psv : $answer\n";
   if ($prev == "*") {$answer = $answer * $psv;}
   if ($prev == "+") {$answer = $answer + array_pop($numstack);}
   array_pop($opstack);
  }
 } else {
  array_push($opstack,$o);
  array_push($numstack,$n);
 }
 }

echo $answer;
}

function array_peek($a) {
 return @$a[sizeof($a)-1];
}

?>
<body  onload='document.form.val.focus();'>
<form name='form'>
<input name='val'>
<input type=submit>
</form>
</body>